package leetcode.median;

import java.util.LinkedList;
import java.util.List;

/**
 * ClassName: $797_AllPathsSourceTarget
 * Description:
 * date: 2021-12-15 9:19
 *
 * @author liyifan
 */
public class $797_AllPathsSourceTarget {

    List<List<Integer>> res = new LinkedList<>();

    public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
        LinkedList<Integer> path = new LinkedList<>();
        traverse(graph, 0, path);
        return res;
    }

    public void traverse(int[][] graph, int now, LinkedList<Integer> path) {
        path.addLast(now);

        int n = graph.length;
        if (now == n - 1) {
            res.add(new LinkedList<>(path));
            path.removeLast();
            return;
        }
        for (int v:graph[now]) {
            traverse(graph, v, path);
        }
        path.removeLast();
    }
}
